package com.macro.mall.controller;

import cn.hutool.core.util.StrUtil;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsSite;
import com.macro.mall.service.PmsSiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * PmsSite的路由接口服务
 *
 * @author
 */
@RestController
@RequestMapping("site")
@Api(tags = "PmsSiteController", description = "场馆管理")
public class PmsSiteController {

    /**
     * PmsSiteService服务
     */
    @Autowired
    private PmsSiteService pmsSiteService;

    /**
     * 查询所有PmsSite数据的方法
     *
     * @return
     */
    @ApiOperation("查询list")
    @RequestMapping(value = "/list",  method = RequestMethod.GET)
    public CommonResult find(@ApiParam(value = "场馆名称") @RequestParam(value = "siteName", defaultValue = "") String siteName,
                             @ApiParam(value = "机构id")  @RequestParam(value = "deptId", defaultValue = "") String deptId,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize ) {
        List<PmsSite> pmsSites = pmsSiteService.find(PmsSite.builder().deptId(StrUtil.isBlankIfStr(deptId) ? null : Integer.parseInt(deptId))
                .siteName(siteName)/*.status("01")*/
                .build(), pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(pmsSites));
    }

    /**
     * 通过id查询PmsSite数据的方法
     *
     * @param id
     * @return
     */
    @ApiOperation("通过id查询")
    @RequestMapping(value = "/findOneById", method = RequestMethod.GET)
    public CommonResult findOne(@RequestParam(value = "id") Integer id) {
        PmsSite one = pmsSiteService.findOne(id);
        return CommonResult.success(one);
    }

    /**
     * 插入PmsSite属性不为空的数据方法
     *
     * @param
     * @return
     */
    @ApiOperation("添加")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult save(@Valid @RequestBody PmsSite value) {
        return pmsSiteService.saveNotNull(value);
    }

    /**
     * 更新PmsSite属性不为空的数据方法
     *
     * @return
     */
    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult update(@Valid @RequestBody PmsSite value) {
        return pmsSiteService.updateNotNullById(value);
    }

    /**
     * 通过id删除PmsSite数据方法
     *
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public CommonResult delete(@RequestParam(value = "id") Integer id) {
        return pmsSiteService.deleteById(id);
    }
}
